#pragma semicolon 1
//#pragma newdecls required
#include <sourcemod>
#include <sdktools>

#define PLUGIN_NAME                   "l4d2_tank_attack_jump"    //这里写插件名字
#define PLUGIN_AUTHOR                 "豆瓣酱な"                         //作者
#define PLUGIN_DESCRIPTION            "特感受到攻击跳起来."   //介绍
#define PLUGIN_VERSION                "1.0"
#define PLUGIN_URL                    "https://gitee.com/sweet-and-sour-bombs"  //网站
new g_iVelocity	= -1;

public Plugin myinfo =
{
    name        = PLUGIN_NAME,
    author      = PLUGIN_AUTHOR,
    description = PLUGIN_DESCRIPTION,
    version     = PLUGIN_VERSION,
    url         = PLUGIN_URL
}

new Handle:sm_tank_rocket			= INVALID_HANDLE;

public void OnPluginStart()
{
	sm_tank_rocket	 	= CreateConVar("sm_tank_rocket", "1", "tank被击中后是否跳跃(0:OFF 1:ON)", FCVAR_NOTIFY);
	HookEvent("player_hurt", Event_PlayerHurt, EventHookMode_Pre);
	if((g_iVelocity = FindSendPropOffs("CBasePlayer", "m_vecVelocity[0]")) == -1)
	LogError("Could not find offset for CBasePlayer::m_vecVelocity[0]");
	
}


public Action:Event_PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
{
	new client = GetClientOfUserId(GetEventInt(event, "attacker"));
	new target = GetClientOfUserId(GetEventInt(event, "userid"));
	
	decl String:weapon[64];
	GetEventString(event, "weapon", weapon, sizeof(weapon));
	
	if(client <= 0 || client > GetMaxClients())
		return;
	if(!IsValidEntity(client) || !IsClientInGame(client))
		return;
	if(!IsValidEntity(target) || !IsClientInGame(target))
		return;

		/* Boomer jumps when hurted */
	if(GetEntProp(target, Prop_Send, "m_zombieClass") == 8 && GetConVarInt(sm_tank_rocket))    //1= smoker, 2= boomer, 3=hunter, 4=spitter, 5=jockey, 6=charger, 7=无，8=tank, 1-8击飞特感, 9 =全部特感能击飞玩家,
	{
		AddVelocity(target, 0.0, 500.0); //这里改击飞高度.
		
	}

}

public AddVelocity(client, Float:xSpeed, Float:zSpeed)
{
	if(g_iVelocity == -1) return;
	
	new Float:vecVelocity[3];
	GetEntDataVector(client, g_iVelocity, vecVelocity);
	
	if(GetRandomInt(0, 1))
	{
		vecVelocity[0] -= xSpeed;
	}
	else
	{
		vecVelocity[0] += xSpeed;
	}
	
	if(GetRandomInt(0, 1))
	{
		vecVelocity[1] -= xSpeed;
	}
	else
	{
		vecVelocity[1] += xSpeed;
	}
	vecVelocity[2] += zSpeed;
	
	TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, vecVelocity);

}









































